export default {
    
    //所有的数据都放在state中
    state: {
        // menu: [],
        // tabsList: ['首页'],
        // currentMenu: null
        tabList: [
            {
                'path': '/home',
                'name' : '首页',
                'select': true
            }
        ]
    },

    //操作数据，唯一的通道是mutations
    mutations: {
        selectMemu(state,tab) {
            // if("首页" == val) {
            //     state.currentMenu = null
            // }else {
            //     state.currentMenu = val
            //     let result = state.tabsList.findIndex(item => item == val);
            //     result == -1 ? state.tabsList.push(val) : ''
            // }
            if("/home" == tab.path) {
                if(state.tabList.length > 1) {
                    state.tabList.forEach(item => {
                        item.select = false
                    })
                }
                state.tabList[0].select = true;
            }else {
                let result = state.tabList.findIndex(item => item.path == tab.path);//查看是否有重复
                if(result == -1) {//没有重复
                    state.tabList.forEach(item => {
                        item.select = false
                    })
                    // console.log(tab);
                    tab.select = true
                    state.tabList.push(tab);
                }else {//有重复的数据
                    // console.log('将要演示的tag: ',tab)
                    state.tabList.forEach(item => {
                        if(item.path == tab.path) {
                            item.select = true;
                        }else {
                            item.select = false;
                        }
                    })
                }
            }
            // console.log("tabList: ",state.tabList);
        },
        closeTab(state,tab) {
            let result = state.tabList.findIndex(item => item.path == tab.path);
            state.tabList.splice(result,1)
        }
    },

    //actions,可以来做异步操作，然后提交给mutations，而后再对state(数据)进行操作
    actions: {}
}